﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace OurMemory
{
    public partial class FormEditPS : Form
    {
        private readonly ProblemSolvingServices services = new ProblemSolvingServices();

        /// <summary>
        /// 当前记录的id
        /// </summary>
        private Guid id;
        public FormEditPS()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 从上级窗体导入id
        /// </summary>
        /// <param name="id"></param>
        public FormEditPS(Guid id)
        {
            InitializeComponent();
            panel1.BackgroundImage = Image.FromFile(@"C:\Users\月亮\Desktop\final-projecte2-master\OurMemory\Properties\bg2.jpg");
            panel1.BackgroundImageLayout = ImageLayout.Stretch;

            this.ClientSize = new Size(450, 400); // 设置客户区大小

            var item = services.GetById(id);
            if (item != null)
            {
                textRecorder.Text = item.Recorder;
                textProblem.Text = item.Problem;
                dTP.Value = item.Date;
                textUrgency.Text = item.Urgency;
                this.id = id;
            }
        }

        /// <summary>
        /// 取消操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnok_Click(object sender, EventArgs e)
        {
            ProblemSolvingEditModel model = new ProblemSolvingEditModel()
            {
                Id = this.id,
                Recorder = textRecorder.Text,
                Problem = textProblem.Text,
                Date = dTP.Value.Date,
                Urgency = textUrgency.Text,
            };
            services.Edit(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
